

import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

function submitAddRefer(postData) {
    return proFetch({
        url: '/nccloud/hrhi/keypsn/KeyPsnRefAddDoAction.do',
        body: postData
    });
}


export default function() {

    const {
        syncTree,
        meta,
        form
    } = this.props;
    let {
        currentSelectDepartment,
        humanResourceOrganizationValue
    } = this.state;

    let treeData = syncTree.getSyncTreeValue('keyPsnGroupTree', currentSelectDepartment);
    let postData = {
        pk_keypsn_group: treeData.nodeData.nodeValue['pk_keypsn_group'],
        pk_org: humanResourceOrganizationValue.refpk
    };
    proFetch({
        url: '/nccloud/hrhi/keypsn/KeyPsnRefAddCheckAction.do',
        body: postData
    })
        .then((res) => {
            this.setState({
                addReferConfig: {
                    refcode: res.data.refpath,
                    clickContainer: <div ref={ref => this.addReferRef = ref}></div>,
                    isMultiSelectedEnabled: true,
                    queryCondition: () => {
                        return res.data.refParam;
                    },
                    onChange: (value) => {
                        let postData = {
                            param_str: value.map(item => item.refpk).join(','),
                            pk_keypsn_group: treeData.nodeData.nodeValue['pk_keypsn_group'],
                            pk_org: humanResourceOrganizationValue.refpk
                        };
                        submitAddRefer(postData)
                            .then((res) => {
                                if(res.success) {
                                    this.getMainTableData();
                                }
                            });
                    }
                }
            })
        });
}